package com.chinasoft.ssm.controller;


import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.chinasoft.ssm.mapper.ItemMapper;
import com.chinasoft.ssm.pojo.Item;
import com.chinasoft.ssm.pojo.Result;
import com.chinasoft.ssm.service.ItemService;
import com.chinasoft.ssm.service.OrderhisService;
import com.chinasoft.ssm.util.AlipayConfig;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.DecimalFormat;
import java.util.*;

@RestController
@CrossOrigin
@Slf4j
public class ItemController {
    @Autowired
    ItemService bikeService;
    @Autowired
    ItemMapper mapper;

    @Autowired
    OrderhisService orderhisService;
    @DeleteMapping("/itemdel/{id}")
    public Result delete(@PathVariable Integer id)
    {
        Result result = new Result();
        Integer data = bikeService.delete(id);
        result.setData(data);
        result.setMessage("删除成功");
        result.setStatus(200);
        return result;
    }
//    @GetMapping("/bike/selectPage")
//    Result selectPage(Integer current, Integer size) {
//        System.out.println(current + " " + size);
//        // 计算从第几条记录开始
////        Integer start = (current - 1) * size;
//        PageHelper.startPage(current, size);
//
//        Result result = new Result();
//        List<Bike> brands = mapper.findAll();
//        // Page 类 是 List的子类
//        Page<Bike> info = (Page<Bike>) brands;
//        result.setData(info);
//        result.setMessage("分页成功");
//        result.setStatus(200);
//        return result;
//    }

    @GetMapping("/itemsell/{userId}")
    public Result cat(@PathVariable Integer userId) {
        Result result = new Result();
        List<Item> data = bikeService.select(userId);
        result.setData(data);
        log.info(result.getData().toString());
        result.setMessage("查询成功");
        result.setStatus(200);
        log.info(result.toString());
        return result;
    }

    @GetMapping("/itemsel/{id}/{userid}")
    public Result cat1(@PathVariable Integer id,@PathVariable Integer userid) {
        Result result = new Result();
        List<Item> data = bikeService.selectbyId(id,userid);
        if(data!=null){
            log.info("xxxx");
        result.setData(data);
        log.info(data.toString());
        result.setMessage("查询成功");
        result.setStatus(200);}
        else
        {    result.setData(1);
            result.setMessage("查询shibai");
            result.setStatus(400);
            log.info(String.valueOf(result.getStatus()));
        }
        return result;
    }
    @PostMapping("/itemins")
    public Result insert(@RequestBody Item bike) {
        Result result = new Result();
        Integer data = bikeService.insert(bike);
        log.info("111");
        result.setData(data);
//        System.out.println(data);
        result.setMessage("插入成功");
        result.setStatus(200);
        return result;
    }

    @PostMapping("/itemupd")
        public Result update(@RequestBody Item bike)
        {
            Result result = new Result();
            Integer data = bikeService.update(bike);
            log.info("修改成功");
            result.setData(data);
            result.setMessage("修改成功");
            result.setStatus(200);
            return result;

        }




}
